﻿using System;
using System.Collections.Generic;
using System.Text;
using MapReduce.Comm;
using System.Threading;

namespace MapReduce.Services
{
    public class OutputService : IService
    {
        public byte[][] Execute(byte[][] pData)
        {
            String callbackGuid = U.Convert(pData[0]).ToString();
            byte opStatus = pData[1][0];


            //create an output array that will not have first 2 elements
            byte[][] opArr = new byte[pData.Length-2][];
            for (int i = 2; i < pData.Length; i++)
            {
                opArr[i - 2] = pData[i];
            }

            JobRequest.Callback callback = JobCallbackPool.Release(callbackGuid);
            callback(opStatus, opArr);

            return new byte[][] { U.GetBytes("1") };
        }
    }
}
